package com.atguigu.chapter13

object ParameterInfer {
  def main(args: Array[String]): Unit = {
    val list = List(1, 2, 3, 4)
    println(list.map((x: Int) => x + 1)) //(2,3,4,5)
    // 可以使用类型推断,所以数据类型可以去掉
    println(list.map(x => x + 1)) //(2,3,4,5)
    println(list.map(x => x + 1)) //(2,3,4,5)
    println(list.map(_ + 1)) //(2,3,4,5)
    println(list.reduce(f1)) // 10
    println(list.reduce((n1: Int, n2: Int) => n1 + n2)) //10
    println(list.reduce((n1, n2) => n1 + n2)) //10
    println(list.reduce(_ + _)) //10
    val res = list.reduce(_ + _)
    print(res)
    println("简化写法")
    println(list.sum) //10
    println(list.sum) //10
    println(list.sum) //10
    val res2 = list.sum
    print(res2)
  }

  def f1(n1: Int, n2: Int): Int = {
    n1 + n2
  }
}
